package cn.wl.hrm.web.controller;


import cn.wl.hrm.doc.CourseDoc;
import cn.wl.hrm.query.CourseQuery;
import cn.wl.hrm.repository.CourseElasticsearchRepository;
import cn.wl.hrm.service.ESService;
import cn.wl.hrm.util.AjaxResult;
import cn.wl.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ESController {
    @Autowired
    private CourseElasticsearchRepository courseElasticsearchRepository;

    @Autowired
    private ESService esService;

    @RequestMapping(value = "/es/onLineCourse",method = RequestMethod.POST)
    public AjaxResult onLineCourse(@RequestBody CourseDoc doc){
        courseElasticsearchRepository.save(doc);
        return AjaxResult.me();
    }

    @RequestMapping(value = "/es/offLineCourse",method = RequestMethod.POST)
    public AjaxResult offLineCourse(@RequestParam("id") Long id){
        courseElasticsearchRepository.deleteById(id);
        return AjaxResult.me();
    }

    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public PageList<CourseDoc> searchCourse(@RequestBody CourseQuery courseQuery){
        return esService.searchCourse(courseQuery);
    }

}
